<?php 
class LeaveAction extends BaseAction
{
	public function index()
	{
			
			if ( $_GET['seek'] == 1 )
			{
			
				//搜索字段数组
				$field = array(
						'ly_name',
						'ly_id',	
				);
		
				$seek = common_html_Arr($_GET);
			
				//过滤空数组
				$seek = common_filtration($seek);
				
				//过滤非法字段
				foreach ( $seek as $k=>$v )
				{
						
					if ( !in_array($k, $field) )
					{
						unset($seek[$k]);
						continue;
					}
					
					
					
					$k == 'ly_name' ? $seekStr .= "LOCATE('{$v}',{$k}) > 0  and " : $seekStr .= $k."='{$v}' and ";
						
				}
			//die($seekStr);
			}
			
			
				
			//载入分页扩展类
			import('ORG.Util.Page');
				
			//实例化model
			$LeaveModel = new LeaveModel();
			
			$count = $LeaveModel->getCount($seekStr);
			
			//实例化分页类
			$page = new Page($count, 8);
				
			//分页字符
			$pageStr = $page->firstRow.','.$page->listRows;
				
			$results = $LeaveModel->getListAll($pageStr, $seekStr);
			
			//die(P($results));
			
			//数据重装
			foreach ( $results as $k=>&$v )
			{
				//时间格式转化
				$v['add_time'] = date('Y-m-d', $v['add_time']);
				//省略
				$v['content']=common_subtext($v['content'],40);

			}
			//die(P($results));
			//变量注入
			
			$this->results = $results;

			$this->show = $page->show();
			
			$this->display();
	}
	/**
	 * 更新（插入）视图
	 */
	public function update()
	{
	
		//更新
		if ( common_is_number($_GET['id']) )
		{
	
			$id = common_html_Arr($_GET['id']);
	
			//model
			$LeaveModel = new LeaveModel();
	
			//获取指定id数据
			$result = $LeaveModel->getRowById($id);
	
			
			//时间格式转化
			$result['add_time'] = date('Y-m-d', $result['add_time']);

			//die(P($result));
		
			$this->result = $result;
	
			//die(P($result));
	
		}
	
		$this->display();
			
	}
	/**
	 *删除控制
	 */
	public function del()
	{
			
		IS_AJAX || die('非法提交');
			
		$requset = common_html_Arr($_POST);
			
		//WeddingModel model
		$LeaveModel = new LeaveModel();
			
		$result = $LeaveModel->del($requset['check']);
			
		if ( $result > 0 )
		{
			$response['status'] = 1;
	
			$response['info'] = '删除成功';
		}
		else
		{
	
			$response['status'] = 0;
	
			$response['info'] = '删除失败';
	
		}
			
		die(json_encode($response));
	}
}


?>